package com.yangbo.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @Date 2018-10-15 9:36
 */
@Service
public class UserService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "userError")
    public Map<String,Object> userService(String name) {
        return (Map<String,Object>)restTemplate.getForObject("http://EUREKA-CLIENT-PRODUCER/user?name="+name,Object.class);
    }

    public Map<String,Object> userError(String name) {
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("msg","error");
        result.put("code",500);
        result.put("name",name);
        return result;
    }
}
